<template>
	<view>
		<view class="tui-searchbox flex justify-between">
			<view class="tui-search-input">
				<icon type="search" :size='13' color='#666'></icon>
				<input confirm-type="search" placeholder="请输入关键词" v-model="kw" @confirm="search()"  placeholder-class="tui-input-plholder"
				 class="tui-input ml-2" />
			</view>
		</view>

		<view class="tui-product-box">
			<view class="tui-product-list">
				<view class="tui-product-container">
					<block v-for="(item,index) in goodsList" :key="index" v-if="(index+1)%2!=0">
						<!--商品列表-->
						<view class="tui-pro-item" hover-class="hover" :hover-start-time="150" @tap="goodsDetail(item)">
							<image :src="item.thumbnail" class="tui-pro-img" mode="widthFix" />
							<view class="tui-pro-content">
								<view class="tui-pro-tit">{{item.title}}</view>
								<view>
									<view class="tui-pro-price">
										<text class="tui-sale-price">￥{{item.price}}</text>
										<text class="tui-factory-price">￥{{item.original_price}}</text>
									</view>
								</view>
							</view>
						</view>
						<!--商品列表-->
					</block>
				</view>
				<view class="tui-product-container">
					<block v-for="(item,index) in goodsList" :key="index" v-if="(index+1)%2==0">
						<!--商品列表-->
						<view class="tui-pro-item" hover-class="hover" :hover-start-time="150" @tap="goodsDetail(item)">
							<image :src="item.thumbnail" class="tui-pro-img" mode="widthFix" />
							<view class="tui-pro-content">
								<view class="tui-pro-tit">{{item.title}}</view>
								<view>
									<view class="tui-pro-price">
										<text class="tui-sale-price">￥{{item.price}}</text>
										<text class="tui-factory-price">￥{{item.original_price}}</text>
									</view>
								</view>
							</view>
						</view>
						<!--商品列表-->
					</block>
				</view>
			</view>
		</view>
		
		<!--加载loadding-->
		<tui-loadmore :visible="loadding" :index="3" type="red"></tui-loadmore>
		<tui-nomore :visible="!pullUpOn"></tui-nomore>

	</view>
</template>

<script>
var api = require('@/common/api.js')
import tuiLoadmore from "@/components/loadmore/loadmore"
import tuiNomore from "@/components/nomore/nomore"
export default {
	components:{
		tuiLoadmore,
		tuiNomore,
	},
	data() {
		return {
			goodsList:[],
			kw:"",
			pageIndex:1,
			pullUpOn:true,
			loadding:false
		};
	},
	onLoad: function(options) {
		console.log(options);
		this.kw = options.kw
		if(this.kw != ""){
			this.getGoodsList();
		}
	},
	methods: {
		getGoodsList:function(){
			if(!this.pullUpOn) return;
			api.get({
				url:"mall/item",
				data:{
					kw:this.kw,
					page:this.pageIndex+',10'
				},
				success:res=>{
					if(res.code == 1){
						this.goodsList = this.goodsList.concat(res.data);
						if(res.data.length < 10){
							this.pullUpOn = false;
						}
						this.pageIndex ++ 
					}
				}
			})
		},
		search:function(){
			this.pageIndex = 1;
			this.loadding = false;
			this.pullUpOn = true;
			this.goodsList = [];
			this.getGoodsList()
		},
		goodsDetail(item){
			uni.navigateTo({
				url:"/pages/mall-extend/productDetail/productDetail?id="+item.id
			})
		},
	},
	onReachBottom() {
		this.getGoodsList();
	}
};
</script>

<style>
page {
	background: #fcfcfc;
}

/* 左侧导航布局 start*/

/* 隐藏scroll-view滚动条*/

::-webkit-scrollbar {
	width: 0;
	height: 0;
	color: transparent;
}

.tui-searchbox {
	width: 100%;
	height: 92rpx;
	padding: 0 30rpx;
	box-sizing: border-box;
	background: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	position: fixed;
	left: 0;
	top: 0;
	/* #ifdef H5 */
	top: 44px;
	/* #endif */
	z-index: 100;
}

.tui-searchbox::after {
	content: '';
	position: absolute;
	border-bottom: 1rpx solid #d2d2d2;
	-webkit-transform: scaleY(0.5);
	transform: scaleY(0.5);
	bottom: 0;
	right: 0;
	left: 0;
}

.tui-search-input {
	width: 100%;
	height: 60rpx;
	background: #f1f1f1;
	border-radius: 30rpx;
	font-size: 26rpx;
	color: #999;
	display: flex;
	align-items: center;
	padding: 0 20rpx;
}

.tui-search-text {
	padding-left: 16rpx;
}

.tab-view {
	/* height: 100%; */
	width: 200rpx;
	position: fixed;
	left: 0;
	z-index: 10;
}

.tab-bar-item {
	width: 200rpx;
	height: 110rpx;
	background: #f6f6f6;
	box-sizing: border-box;
	display: flex;
	align-items: center;
	justify-content: center;
	font-size: 26rpx;
	color: #444;
	font-weight: 400;
}

.active {
	position: relative;
	color: #000;
	font-size: 30rpx;
	font-weight: 600;
	background: #fcfcfc;
}

.active::before {
	content: '';
	position: absolute;
	border-left: 8rpx solid #e41f19;
	height: 30rpx;
	left: 0;
}

/* 左侧导航布局 end*/

	/* 商品列表 */
	.tui-product-box {
		margin-top: 120rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
	}
	
	.tui-pb-20 {
		padding-bottom: 20rpx;
	}
	
	.tui-bg-white {
		background: #fff;
	}
	
	.tui-group-name {
		font-size: 32rpx;
		font-weight: bold;
		text-align: center;
		padding: 24rpx 0;
	}
	
	.tui-activity-box {
		display: flex;
		border-radius: 12rpx;
		overflow: hidden;
	}
	
	.tui-activity-img {
		width: 50%;
		display: block;
	}
	
	.tui-new-box {
		display: flex;
		align-items: center;
		justify-content: space-between;
		flex-wrap: wrap;
	}
	
	.tui-new-item {
		width: 49%;
		height: 200rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		background: #f5f2f9;
		position: relative;
		border-radius: 12rpx;
	}
	
	.tui-new-mtop {
		margin-top: 2%;
	}
	
	.tui-title-box {
		font-size: 24rpx;
	}
	
	.tui-new-title {
		line-height: 32rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
	
	.tui-new-price {
		padding-top: 18rpx;
	}
	
	.tui-new-present {
		color: #ff201f;
		font-weight: bold;
	}
	
	.tui-new-original {
		display: block;
		color: #a0a0a0;
		text-decoration: line-through;
		font-size: 20rpx;
	}
	
	.tui-new-img {
		width: 160rpx;
		height: 160rpx;
		display: block;
		flex-shrink: 0;
	}
	
	.tui-new-label {
		width: 56rpx;
		height: 56rpx;
		border-top-left-radius: 12rpx;
		position: absolute;
		left: 0;
		top: 0;
	}
	
	.tui-product-list {
		display: flex;
		justify-content: space-between;
		flex-direction: row;
		flex-wrap: wrap;
		box-sizing: border-box;
		/* padding-top: 20rpx; */
	}
	
	.tui-product-container {
		flex: 1;
		margin-right: 2%;
	}
	
	.tui-product-container:last-child {
		margin-right: 0;
	}
	
	.tui-pro-item {
		width: 100%;
		margin-bottom: 4%;
		background: #fff;
		box-sizing: border-box;
		border-radius: 12rpx;
		overflow: hidden;
	}
	
	.tui-pro-img {
		width: 100%;
		display: block;
	}
	
	.tui-pro-content {
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		box-sizing: border-box;
		padding: 20rpx;
	}
	
	.tui-pro-tit {
		color: #2e2e2e;
		font-size: 26rpx;
		word-break: break-all;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
		-webkit-line-clamp: 2;
	}
	
	.tui-pro-price {
		padding-top: 18rpx;
	}
	
	.tui-sale-price {
		font-size: 34rpx;
		font-weight: 500;
		color: #e41f19;
	}
	
	.tui-factory-price {
		font-size: 24rpx;
		color: #a0a0a0;
		text-decoration: line-through;
		padding-left: 12rpx;
	}
	
	.tui-pro-pay {
		padding-top: 10rpx;
		font-size: 24rpx;
		color: #656565;
	}
</style>
